﻿#region File Description
//-----------------------------------------------------------------------------
// GalaxyComponent.cs
//
// Microsoft XNA Community Game Platform
// Copyright (C) Microsoft Corporation. All rights reserved.
//-----------------------------------------------------------------------------
#endregion

#region Using Statements
using System;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
#endregion


namespace FUSE
{
    /// <summary>
    /// Galaxy Component (Abstract Object)
    ///  all object stored in galaxy map with exception of the ship should inherit properties from galaxy component
    ///  galaxy map’s collection array should store each of the objects as galaxy components
    ///  Galaxy Component Requirements
    /// </summary>
    public abstract class GalaxyComponent
    {

        /// <summary>
        /// Name of the galaxy component
        /// </summary>
        private String name = "unknown Component";
        private Texture2D componentTexture;

        private Circle componentBounds;

        private Vector2 renderPosition;
        protected String[] consonants = new String[] { "b", "c", "d", "f", "g", "h", "j", "k", "l", "m", "n", "p", "r", "s", "t", "v", "w", "x", "z" };
        protected String[] Consonants = new String[] { "B", "C", "D", "F", "H", "H", "J", "K", "L", "M", "N", "P", "R", "S", "T", "V", "W", "X", "Z" };
        protected String[] vowels = new String[] { "a", "e", "i", "o", "u", "y" };



        /// <summary>
        /// Creates a new shape. Calls the virtual Create method to generate any vertex buffers etc
        /// </summary>
        public GalaxyComponent()
        {
            componentBounds = new Circle();
            renderPosition = new Vector2();
        }

        public virtual void Initialize()
        {
            if (componentBounds.radius == 0)
            {
                renderPosition = Vector2.Zero;
                componentBounds.centerPOS = Vector2.Zero;
                componentBounds.radius = 1;
            }
            else
                this.SetRenderPosition(0, 0);
        }

        public virtual void LoadContent(Texture2D newTexture)
        {
            componentTexture = newTexture;
            componentBounds.SetPosition(new Vector2((newTexture.Width / 2), (newTexture.Height / 2)));
            componentBounds.radius = Math.Min(newTexture.Height / 2, newTexture.Width / 2);            
        }
        
        public virtual void SetRenderPosition(float xCoord, float yCoord)
        {
            renderPosition = new Vector2(xCoord, yCoord);
            componentBounds.SetPosition(
                new Vector2(xCoord + (componentTexture.Width / 2),
                yCoord + (componentTexture.Height / 2)));
        }

        public virtual void SetCenterPosition(float xCoord, float yCoord)
        {
            componentBounds.SetPosition(new Vector2(xCoord, yCoord));
            renderPosition = new Vector2(xCoord - (componentTexture.Width / 2),
                yCoord - (componentTexture.Height / 2));
        }

        /// <summary>
        /// Updates the shape. Base class does nothing
        /// </summary>
        /// <param name="time">Game Time</param>
        public void Update(GameTime gameTime)
        {
            //Nothing for now
        }

        public double Distance(GalaxyComponent otherCenterPosition)
        {
            double dist = 0;
            dist = Math.Sqrt(Math.Pow((componentBounds.centerPOS.X - otherCenterPosition.componentBounds.centerPOS.X), 2) +
                Math.Pow((componentBounds.centerPOS.Y - otherCenterPosition.componentBounds.centerPOS.Y), 2));
            return dist;
        }

        public virtual void Draw(SpriteBatch spriteBatch)
        {
            spriteBatch.Draw(componentTexture, renderPosition, Color.White); 
        }

        public virtual Boolean Intersects(GalaxyComponent otherGalaxyComponent)
        {
            return this.componentBounds.Intersects(otherGalaxyComponent.componentBounds);
        }

        public Circle ComponentBounds
        {
            get { return componentBounds; }
        }

        public String Name
        {
            get { return name; }
            set { name = value; }
        }

        public Vector2 RenderPosition
        {
            get { return renderPosition; }
            set
            {
                renderPosition.X = value.X;
                renderPosition.Y = value.Y;
            }
        }

        public Texture2D ComponentTexture
        {
            get { return componentTexture; }
        }
    }
}
